package com.example.blog.controller;

import com.example.blog.base.Result;
import com.example.blog.entity.FavoritesFolders;
import com.example.blog.entity.dto.favoritesFolders.FavoritesFoldersAddOrUpdateDTO;
import com.example.blog.entity.vo.favoritesFolders.FavoritesFoldersVO;
import com.example.blog.service.FavoritesFoldersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏夹模块
 * @ClassName FavoritesFoldersController
 * @Description TODO
 * @Author Wang Li Hong
 * @date 2024/1/15 15:02
 * @Version 1.0
 */

@RestController
@RequestMapping("/blog/favorites_folders")
public class FavoritesFoldersController {


    @Autowired
    private FavoritesFoldersService favoritesFoldersService;

    /**
     * 新增或修改收藏夹
     * @param favoritesFoldersAddOrUpdateDTO
     * @return
     */
    @PostMapping("/add-or-update")
    public Result<Void> add(@RequestBody @Validated FavoritesFoldersAddOrUpdateDTO favoritesFoldersAddOrUpdateDTO) {
        favoritesFoldersService.add(favoritesFoldersAddOrUpdateDTO);
        return Result.success();
    }

    /**
     * 根据ID删除收藏夹
     * @param id 收藏夹ID
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Void> del(@PathVariable Long id) {
        favoritesFoldersService.removeById(id);
        return Result.success();
    }

    /**
     * 获取自己的收藏夹列表
     * @return
     */
    @GetMapping("/list")
    public Result<List<FavoritesFoldersVO>> dataList() {
        List<FavoritesFoldersVO> data = favoritesFoldersService.dataList();
        return Result.successData(data);
    }

    /**
     * 根据用户id获取公开的收藏夹列表
     * @param userId
     * @return
     */
    @GetMapping("/public-list")
    public Result<List<FavoritesFoldersVO>> publicList(@RequestParam("userId") Long userId) {
        List<FavoritesFoldersVO> data = favoritesFoldersService.publicList(userId);
        return Result.successData(data);
    }
}
